using System;
using System.Collections.Generic;
using System.Text;

namespace MoGameLib
{
    public class TerrainCollection : ICollection<Terrain>
    {
        #region ICollection<Terrain> Members

        protected Dictionary<string, Terrain> m_Terrains = new Dictionary<string,Terrain>();

        public void Add(Terrain item)
        {
            // TODO: assert if char is already there
            m_Terrains.Add(item.IDChar, item);
        }

        public void Clear()
        {
            m_Terrains.Clear();
        }

        public bool Contains(Terrain item)
        {
            return m_Terrains.ContainsValue(item);
        }

        public void CopyTo(Terrain[] array, int arrayIndex)
        {
            m_Terrains.Values.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return m_Terrains.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(Terrain item)
        {
            return m_Terrains.Remove(item.IDChar);
        }

        #endregion

        #region IEnumerable<Terrain> Members

        public IEnumerator<Terrain> GetEnumerator()
        {
            return m_Terrains.Values.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        public Terrain GetTerrain(string idChar)
        {
            return m_Terrains[idChar];
        }

        public Terrain Create(string idChar)
        {
            Terrain newTerrain = new Terrain();
            newTerrain.IDChar = idChar;
            Add(newTerrain);
            return newTerrain;
        }
    }
}
